<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Brand extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        $category_id = (int)$this->request->param('category_id');
        $brand = Db::name('brand')->where(['category_id' => $category_id, 'status' => 1])->field('id,name,logo,flag')->select();
        $this->assign('brand', json_encode($brand));
        $this->assign('title', '品牌');
        return $this->view->fetch();
    }

    public function business_info()
    {
        $this->assign('title', '商家详情');
        return $this->view->fetch();
    }

    public function info($id)
    {
        $brand = Db::name('brand')->where(['id' => $id])->find();
        if(!$brand) {
            $this->error('页面不存在');
        }
        $news = Db::name('brand_news')->where(['brand_id' => $id])->limit(10)->select();
        $this->assign('brand', $brand);
        $this->assign('news', $news);
        $this->assign('title', '品牌详情');
        return $this->view->fetch();
    }

    public function news_info($id)
    {
        $info = Db::name('brand_news')->where(['id' => $id])->find();
        if(!$info) {
            $this->error('页面不存在');
        }
        $this->assign('info', $info);
        $this->assign('title', $info['title']);
        return $this->view->fetch();
    }

}
